package com.edu.exam.enums.curriculum.questionbank;

/**
 * 试题属性类型枚举
 *
 * 定义试题扩展属性的数据类型
 *
 * @author System
 * @version 1.0.0
 */
public enum QuestionAttributeType {
    STRING("STRING", "字符串"),
    INTEGER("INTEGER", "整数"),
    DECIMAL("DECIMAL", "小数"),
    BOOLEAN("BOOLEAN", "布尔值"),
    DATE("DATE", "日期"),
    DATETIME("DATETIME", "日期时间"),
    JSON("JSON", "JSON对象"),
    TEXT("TEXT", "长文本"),
    ENUM("ENUM", "枚举值"),
    ARRAY("ARRAY", "数组");

    private final String code;
    private final String description;

    QuestionAttributeType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     */
    public static QuestionAttributeType fromCode(String code) {
        for (QuestionAttributeType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return STRING; // 默认值
    }
}